Clean Craftsmanship: Disciplines, Standards, and Ethics by Robert C. Martin

Clean Craftsmanship: Disciplines, Standards, and Ethics by Robert C. Martin

Author:Robert C. Martin [Robert C. Martin]
Language: eng
Format: epub
Publisher: Addison-Wesley Professional
Published: 2021-10-22T00:00:00+00:00


The next test fails:

@Test public void testFibs() throws Exception { assertThat(fib(0), equalTo(BigInteger.ONE)); assertThat(fib(1), equalTo(BigInteger.ONE)); assertThat(fib(2), equalTo(new BigInteger("2"))); }

We can make this pass by using Unconditional → Selection:

private BigInteger fib(int n) { if (n > 1) return new BigInteger("2"); else return new BigInteger("1"); }

This is perilously close to being more specific than general, though it titillates me with the potential for negative arguments to the fib function.

The next test tempts us to go for the gold:

assertThat(fib(3), equalTo(new BigInteger("3")));



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.